package zhongbo.java.air.monitor.web.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.monitor.model.AirAlertLog;
import zhongbo.java.air.monitor.service.impl.JtsServiceImpl;

@RestController
@RequestMapping("alertLog")
@Api(tags = "警告日志接口")
public class JtsController {
    @Autowired
    private JtsServiceImpl jtsService;


    /* 以下为复用crud controller层 */

    @ApiOperation("手动增加空域告警日志信息")
    @PostMapping("/addAirAlertLog")
    public ResultVo<String> addAirFlightPath(@RequestBody AirAlertLog airAlertLog) {
        String add = jtsService.addAirAlertLog(airAlertLog);
        if (StrUtil.isNotBlank(add)) {
            return ResultVo.ok(add);
        }
        return ResultVo.error("新增空域告警日志记录失败");
    }

    @ApiOperation("修改空域告警日志记录")
    @PutMapping("/updateAirAlertLog")
    public ResultVo<AirAlertLog> updateAirAlertLog(@RequestBody AirAlertLog airAlertLog) {
        AirAlertLog update = jtsService.updateAirAlertLog(airAlertLog);
        if (update != null) {
            return ResultVo.ok(update);
        }
        return ResultVo.error("修改空域告警日志记录失败");
    }

    @ApiOperation("查询一个空域告警日志记录")
    @GetMapping("/getAirAlertLog")
    public ResultVo<AirAlertLog> getAirAlertLog(@RequestParam(defaultValue = "1") String airId) {
        AirAlertLog airAlertLog = jtsService.getAirAlertLogById(airId);
        return ResultVo.ok(airAlertLog);
    }

    @ApiOperation("删除一个空域告警日志记录")
    @DeleteMapping("/deleteAirAlertLog")
    public ResultVo<Integer> deleteAirAlertLog(@RequestParam(defaultValue = "1") String airId) {
        int delete = jtsService.deleteAirAlertLog(airId);
        return ResultVo.ok(delete);
    }


    @ApiOperation("分页获取所有空域告警日志记录")
    @GetMapping("pageAllAirAlertLog")
    public ResultVo<PageVo<AirAlertLog>> page(@RequestParam(required = false) String icaoCode,
                                                      @RequestParam(defaultValue = "1") Integer pageNumber,
                                                      @RequestParam(defaultValue = "1") Integer pageSize) {
        PageVo<AirAlertLog> page = jtsService.page(icaoCode,pageNumber,pageSize);
        return ResultVo.ok(page);
    }

}
